<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models;

use Carbon\Carbon;

/**
 * Class PartnerOrder
 * 
 * @property int $id
 * @property int $uid
 * @property string|null $order_sn
 * @property string|null $product_name
 * @property float|null $amount
 * @property int|null $days
 * @property Carbon|null $end_time
 * @property int $status
 * @property Carbon|null $pay_time
 * @property Carbon|null $create_at
 * @property Carbon|null $update_at
 *
 * @package App\Models
 */
class PartnerOrder extends BaseModels
{
	protected $table = 'zh_partner_order';

	const UN_PAY = 1;

	const PAYED = 2;

	protected $casts = [
		'uid' => 'int',
		'amount' => 'float',
		'days' => 'int',
        'status' => 'int'
	];

	protected $dates = [
		'end_time',
		'pay_time',
		'create_at',
		'update_at'
	];

	protected $appends = [
	    'status_string', 'user'
    ];


	public function getStatusStringAttribute()
    {
        switch ($this->status){
            case self::UN_PAY:
                return '未支付';
            case self::PAYED:
                return '已支付';
            default:
                return '';
        }
    }

    public function getUserAttribute()
    {
        return User::find($this->uid);
    }

	protected $fillable = [
		'uid',
		'order_sn',
		'product_name',
		'amount',
		'days',
		'end_time',
        'status',
		'pay_time',
		'create_at',
		'update_at'
	];
}
